package znbkTopicType.response;

import android.content.Context;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.lancooznbk.R;

import org.apache.commons.lang3.StringEscapeUtils;

import lancooControl.Control;
import znbkTopicType.TktAnswerEditText;
import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;

import static znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity.mEntityCtfd;
import static znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity.mEntityNtxl;
import static znbkTestPaperRdqh.activity.WeekAscensionPaperActivity.mEntityRdqh;
import static znbkTestPaperXtfx.activity.SystemReviewPaperActivity.mEntityXtfx;

/**
 * Created by Administrator on 2018\2\26 0026.
 */

public class ZnbkResponseTktAdapter extends BaseAdapter

{

    private LayoutInflater mInflater;
    private Context mContext;
    //当前试题数量
    private int SumItem;
    //当前试题在当前试卷的ID
    private int PaperID;
    //当前问题小题所在大题的ID
    private int OptionID;
    private int ModelFrom;//试卷来源

    private int tvBlack;
    private int tvBlue;
    private int tvWhite;
    private int tvGreen;
    private int tvRed;
    private int tvGray;


    private ViewHolder holder = null;
    private class ViewHolder {
        WebView mWvContent;
        LinearLayout mLayoutStuAnswerEdt;//作文输入区
        LinearLayout mLayoutCheckAnalysis;//答案回看解析区
        LinearLayout mLayoutStuAnswer;//我的答案显示区域
        LinearLayout mLayoutAnswer;//参考答案显示区域
        LinearLayout mLayoutStuAssess;//自评显示区域
        LinearLayout mLayoutAnalysis;//解析内容区
        LinearLayout mLayoutTvAnswer;//正确答案文字显示区域
        LinearLayout mLayoutTvStuAnswer;//学生答案文字显示区域
        RadioGroup mRgAssess;
        RadioButton mRBtnExcellent;
        RadioButton mRBtnGood;
        RadioButton mRBtnQualified;
        RadioButton mRBtnRange;
        TextView mTvStuAssess;//自评结果
        TextView mTvAnalysis;//解析
        TextView mTvAnswerAmount;//小题总数

        private ViewHolder(View convertView) {
            mWvContent = (WebView) convertView.findViewById(R.id.wv_content);
            mLayoutStuAnswerEdt = (LinearLayout) convertView.findViewById(R.id.layout_stuAnswerEdt);
            mLayoutCheckAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_checkAnalysis);
            mLayoutStuAnswer = (LinearLayout) convertView.findViewById(R.id.layout_stuAnswer);
            mLayoutAnswer = (LinearLayout) convertView.findViewById(R.id.layout_answer);
            mLayoutStuAssess = (LinearLayout) convertView.findViewById(R.id.layout_stuAssess);
            mLayoutAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_analysis);
            mLayoutTvAnswer =  (LinearLayout) convertView.findViewById(R.id.layout_tvAnswer);
            mLayoutTvStuAnswer = (LinearLayout) convertView.findViewById(R.id.layout_tvStuAnswer);
            mRgAssess = (RadioGroup) convertView.findViewById(R.id.rg_assess);
            mRBtnExcellent = (RadioButton) convertView.findViewById(R.id.rbtn_excellent);
            mRBtnGood = (RadioButton) convertView.findViewById(R.id.rbtn_good);
            mRBtnQualified = (RadioButton) convertView.findViewById(R.id.rbtn_qualified);
            mRBtnRange = (RadioButton) convertView.findViewById(R.id.rbtn_range);
            mTvStuAssess = (TextView) convertView.findViewById(R.id.tv_stuAssess);
            mTvAnalysis = (TextView) convertView.findViewById(R.id.tv_analysis);
            mTvAnswerAmount = (TextView) convertView.findViewById(R.id.tv_answerAmount);
        }
    }

    /*
   * 获取小题选项信息
   * */
    private int itemIndex ;//小题编号
    private String subChildAsk;//小题题干信息
    private String typeName;
    private int status;//试卷的作答状态
    private int isAssess;//本题是否可自评
    private String stuAssess;//自评/机评结果
    private String stuAnswer;//用户答案
    private String answer;//正确答案
    private double score;//试题总分值
    private String analysis;//答案解析
    private String macAssess;//机评
    private int totalItemCount;//小题数量
    public ZnbkResponseTktAdapter(Context context, int sumItem, int paperID, int optionID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.SumItem = sumItem;
        this.PaperID = paperID;
        this.OptionID = optionID;
        this.ModelFrom = modelFrom;

        tvBlack = mContext.getResources().getColor(R.color.black);
        tvBlue = mContext.getResources().getColor(R.color.blue);
        tvWhite = mContext.getResources().getColor(R.color.white);
        tvGreen = mContext.getResources().getColor(R.color.green);
        tvRed = mContext.getResources().getColor(R.color.red);
        tvGray = mContext.getResources().getColor(R.color.gray);
    }

    @Override
    public int getCount() {
        return SumItem;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.znbk_adapter_response_tkt_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        /*
        * 获取作文题用户相关信息
        * */
        getQuesInfor();

        /*
        * 显示题干信息
        * */
        showQuesInfor();

//        /*
//        * 写入用户作答信息
//        * */
//        setEdtStuAnswer();

        /*
        * 显示用户回看解析相关信息
        */
        showAnalysis();

        return convertView;
    }


    private String[] smallAnswer;
    private String[] smallStuAnswer;

    private String mAllAnswer;//回看显示正确答案
    private String mAllStuAnswer;//回看显示学生作答答案

    /*
    * 获取作文题用户相关信息
    * */
    private void  getQuesInfor(){

        if(ModelFrom== ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
            typeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTypeName();
            subChildAsk = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            itemIndex = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getChildIndex();
            stuAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            status = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            answer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            totalItemCount = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTotalItemCount();


        }else if(ModelFrom== ZnbkPaperDef.FROM_WEEK_ASCENSION) {
            typeName = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTypeName();
            subChildAsk = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            itemIndex = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getChildIndex();
            stuAnswer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            status = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            answer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            totalItemCount = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTotalItemCount();


        }else if(ModelFrom== ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {
            typeName = mEntityNtxl.getTKQue().getTypeName();
            subChildAsk = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            stuAnswer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            status = mEntityNtxl.getAnswerState();
            answer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            totalItemCount = mEntityNtxl.getTKQue().getTotalItemCount();

        }else if(ModelFrom == ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){

            if(PaperID==0){
                status = 3;
                typeName = mEntityCtfd.getPrimitiveQues().getTKQue().getTypeName();
                subChildAsk = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                stuAnswer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                answer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                analysis = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                stuAssess = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                totalItemCount = mEntityCtfd.getPrimitiveQues().getTKQue().getTotalItemCount();
            }else{

                if(PaperID==1){
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        status = 3;
                        typeName = mEntityCtfd.getClassicalQues().getTKQue().getTypeName();
                        subChildAsk = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                        stuAnswer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                        answer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                        analysis = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                        stuAssess = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                        totalItemCount = mEntityCtfd.getClassicalQues().getTKQue().getTotalItemCount();
                    }else{
                        status = mEntityCtfd.getRecQues().get(0).getAnswerState();
                        typeName = mEntityCtfd.getRecQues().get(0).getTKQue().getTypeName();
                        subChildAsk = mEntityCtfd.getRecQues().get(0).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                        stuAnswer = mEntityCtfd.getRecQues().get(0).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                        answer = mEntityCtfd.getRecQues().get(0).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                        analysis = mEntityCtfd.getRecQues().get(0).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                        stuAssess = mEntityCtfd.getRecQues().get(0).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                        totalItemCount = mEntityCtfd.getRecQues().get(0).getTKQue().getTotalItemCount();
                    }
                }else{
                    int anotherPaperID = -1;
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        anotherPaperID = PaperID - 2;
                    } else {
                        anotherPaperID = PaperID - 1;
                    }
                    status = mEntityCtfd.getRecQues().get(anotherPaperID).getAnswerState();
                    typeName = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeName();
                    subChildAsk = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                    stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                    answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                    analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                    stuAssess = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                    totalItemCount = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTotalItemCount();
                }
            }
        }

        smallAnswer = new String[totalItemCount];
        for(int i=0;i<totalItemCount;i++){
            smallAnswer[i] = Control.returnArray(answer,"$、",2)[i];
        }

        smallStuAnswer = new String[totalItemCount];
        for(int i=0;i<totalItemCount;i++){
            if(stuAnswer.replaceAll("\\$、","").equals("")){
                smallStuAnswer[i] = "";
            }else{
                smallStuAnswer[i] = Control.returnArray(stuAnswer, "$、", 2)[i];
            }

        }

        String arrayTheme[] = new String[totalItemCount + 1];
        String themeAll = "";
        for (int i = 0; i < totalItemCount + 1; i++) {
            arrayTheme[i] = Control.returnArray(subChildAsk, "____", 4)[i];
            if (i < totalItemCount) {
                themeAll = themeAll + arrayTheme[i] + "<font color='#3399cc'><middle><middle><U>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "（" + (i + 1) + "）" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</U></middle></middle></font>";
            } else {
                themeAll = themeAll + arrayTheme[i];
            }
        }
        subChildAsk = StringEscapeUtils.unescapeXml(themeAll);


    }

    /*
   * 获取题目题干信息
   * */
    private void showQuesInfor(){

        holder.mTvAnswerAmount.setText("本题包含"+totalItemCount+"个小题");
        if(typeName.equals("阅读填空")) {
            holder.mWvContent.loadDataWithBaseURL("about:blank", subChildAsk, "text/html", "utf-8", null);
            holder.mWvContent.getSettings().setDefaultFontSize(18);
        }

        if(status==2||status==3){
            /*
            * 隐藏作答区域
            * */
            holder.mLayoutStuAnswerEdt.setVisibility(View.GONE);
        }else{
            /*
            * 显示作答区域
            * */
            holder.mLayoutStuAnswerEdt.setVisibility(View.VISIBLE);
             /*
            * 写入用户作答信息
            * */
            setEdtStuAnswer();
        }

    }


    private TktAnswerEditText[] TktAnswerEdt;
    /*
    * 用户作答
    * */
    private void setEdtStuAnswer(){

        TktAnswerEdt = new TktAnswerEditText[totalItemCount];
        for(int i=0;i<totalItemCount;i++){

            TktAnswerEdt[i] = new TktAnswerEditText(mContext);

            if (status==2||status==3) {
                TktAnswerEdt[i].setFocusable(false);
                TktAnswerEdt[i].setLongClickable(false);
            }else{
                Log.e("==stuAnswer===","======"+smallStuAnswer[i]);
                if(smallStuAnswer[i].equals("")){
                    TktAnswerEdt[i].EdtStuAnswer.setHint("在此输入答案，提交后请自评");
                }else{
                    TktAnswerEdt[i].EdtStuAnswer.setText(smallStuAnswer[i]);
                }
            }



            TktAnswerEdt[i].TvStuAnswerIndex.setText(String.valueOf(i+1)+".");
            final int finalI = i;
            TktAnswerEdt[i].EdtStuAnswer.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    setIntoStuAnswer(s.toString(), finalI);
                }
            });
            holder.mLayoutStuAnswerEdt.addView( TktAnswerEdt[i]);
        }
    }


    private TextView[] TvStuAnswer;
    private TextView[] TvAnswer;
    /*
    * 显示试题解析回看信息
    * */
    private void showAnalysis(){

        TvStuAnswer = new TextView[totalItemCount];
        TvAnswer = new TextView[totalItemCount];


        /*
        * 系统复习，弱点强化，难题训练
        * */
        if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW||
                ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION||
                ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS||
                ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){

            if(status==0||status==1){
                /*
                * 隐藏答案解析
                * */
                holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
            }else if(status==2||status==3){

                /*
                * 显示答案解析
                * */
                holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                /*
                * 显示我的答案
                * */
                holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                if(stuAnswer.replaceAll("\\$、","").equals("")){
                    for(int i=0;i<totalItemCount;i++){
                        TvStuAnswer[i] = new TextView(mContext);
                        TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                        if(status==3) {
                            TvStuAnswer[i].setTextColor(tvRed);
                        }else if(status==2){
                            TvStuAnswer[i].setTextColor(tvBlue);
                        }
                        TvStuAnswer[i].setTextSize(16);
                        holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                    }
                }else{
                    for(int i=0;i<totalItemCount;i++){
                        TvStuAnswer[i] = new TextView(mContext);
                        if (smallStuAnswer[i].equals(smallAnswer[i])) {
                            TvStuAnswer[i].setTextColor(tvGreen);
                            TvStuAnswer[i].setText(String.valueOf(i+1)+". "+smallStuAnswer[i]);
                        }else{
                            TvStuAnswer[i].setTextColor(tvRed);
                            if(!smallStuAnswer[i].equals("")){
                                TvStuAnswer[i].setText(String.valueOf(i+1)+". "+smallStuAnswer[i]);
                            }else{
                                TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                            }
                        }
                        TvStuAnswer[i].setTextSize(16);
                        holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                    }
                }

                //显示参考答案
                for(int i=0;i<totalItemCount;i++){
                    TvAnswer[i] = new TextView(mContext);
                    TvAnswer[i].setText(Html.fromHtml(String.valueOf(i+1)+". "+smallAnswer[i]));
                    TvAnswer[i].setTextSize(16);
                    TvAnswer[i].setTextColor(tvGreen);
                    holder.mLayoutTvAnswer.addView(TvAnswer[i]);
                }

                //显示自评区域
                holder.mLayoutStuAssess.setVisibility(View.VISIBLE);
                if(status==2){
                    /*
                    * 显示自评选项
                    * 隐藏自评结果
                    * */
                    holder.mRgAssess.setVisibility(View.VISIBLE);
                    holder.mRBtnExcellent.setChecked(false);
                    holder.mRBtnGood.setChecked(false);
                    holder.mRBtnQualified.setChecked(false);
                    holder.mRBtnRange.setChecked(false);
                    if(stuAssess.equals("优秀")){
                        holder.mRBtnExcellent.setChecked(true);
                    }else  if(stuAssess.equals("良好")){
                        holder.mRBtnGood.setChecked(true);
                    }else  if(stuAssess.equals("合格")){
                        holder.mRBtnQualified.setChecked(true);
                    }else  if(stuAssess.equals("较差")){
                        holder.mRBtnRange.setChecked(true);
                    }
                    holder.mRgAssess.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(RadioGroup group, int checkedId) {
                            if(checkedId==holder.mRBtnExcellent.getId()){
                                stuAssess = "优秀";
                            }else if(checkedId==holder.mRBtnGood.getId()){
                                stuAssess = "良好";
                            }else if(checkedId==holder.mRBtnQualified.getId()){
                                stuAssess = "合格";
                            }else if(checkedId==holder.mRBtnRange.getId()){
                                stuAssess = "较差";
                            }
                            if(ModelFrom == ZnbkPaperDef.FROM_SYSTEM_REVIEW){
                                mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                            }else if(ModelFrom == ZnbkPaperDef.FROM_WEEK_ASCENSION){
                                mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                            }else if(ModelFrom == ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {
                                mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                            }

                        }
                    });
                    holder.mTvStuAssess.setVisibility(View.GONE);
                }else if(status==3){
                    /*
                    * 隐藏自评选项
                    * 显示自评结果
                    * */
                    holder.mRgAssess.setVisibility(View.GONE);
                    holder.mTvStuAssess.setVisibility(View.VISIBLE);

                    if(!stuAssess.equals("")) {
                        holder.mTvStuAssess.setText(stuAssess);
                    }else{
                        holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                    }

                }

                //答案解析
                if(status==2){
                    holder.mLayoutAnalysis.setVisibility(View.GONE);
                }else if(status==3){
                    holder.mLayoutAnalysis.setVisibility(View.VISIBLE);
                    if (!analysis.equals("")) {
                        holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                    } else {
                        holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                    }
                    holder.mTvAnalysis.setTextColor(tvBlack);
                }



            }

        }

        /*
        * 错题辅导
        * */
        if (ModelFrom == ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
            if (PaperID == 0) {

                //隐藏作答区域
                holder.mLayoutStuAnswerEdt.setVisibility(View.GONE);
                //显示题目回看解析内容
                holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                //显示我的答案
                holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                if(stuAnswer.replaceAll("\\$、","").equals("")){
                    for(int i=0;i<totalItemCount;i++){
                        TvStuAnswer[i] = new TextView(mContext);
                        TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                        if(status==3) {
                            TvStuAnswer[i].setTextColor(tvRed);
                        }else if(status==2){
                            TvStuAnswer[i].setTextColor(tvBlue);
                        }
                        TvStuAnswer[i].setTextSize(16);
                        holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                    }
                }else{
                    for(int i=0;i<totalItemCount;i++){
                        TvStuAnswer[i] = new TextView(mContext);
                        Log.e("====ABC===","===smallStuAnswer[i]=="+i+"========"+smallStuAnswer[i]);
                        if(status==3) {
                            if (smallStuAnswer[i].equals(smallAnswer[i])) {
                                TvStuAnswer[i].setTextColor(tvGreen);
                            }else {
                                TvStuAnswer[i].setTextColor(tvRed);
                            }
                        }else if(status==2){
                            TvStuAnswer[i].setTextColor(tvBlue);
                        }
                        if(!smallStuAnswer[i].equals("")){
                            TvStuAnswer[i].setText(String.valueOf(i+1)+". "+smallStuAnswer[i]);
                        }else{
                            TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                        }
                        TvStuAnswer[i].setTextSize(16);
                        holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                    }
                }

                //显示参考答案
                holder.mLayoutAnswer.setVisibility(View.VISIBLE);
                for(int i=0;i<totalItemCount;i++){
                    TvAnswer[i] = new TextView(mContext);
                    TvAnswer[i].setText(Html.fromHtml(String.valueOf(i+1)+". "+smallAnswer[i]));
                    TvAnswer[i].setTextSize(16);
                    TvAnswer[i].setTextColor(tvGreen);
                    holder.mLayoutTvAnswer.addView(TvAnswer[i]);
                }

                /*
                * 显示自评区域：holder.mLayoutStuAssess  -->VISIBLE
                * 显示自评结果：holder.mTvStuAssess  -->VISIBLE
                * 隐藏自评选项：holder.mRgAssess  -->GONE
                * */
                holder.mLayoutStuAssess.setVisibility(View.VISIBLE);
                holder.mTvStuAssess.setVisibility(View.VISIBLE);
                holder.mRgAssess.setVisibility(View.GONE);
                if(!stuAssess.equals("")) {
                    holder.mTvStuAssess.setText(stuAssess);
                }else{
                    holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                }

                /*
                * 显示答案解析：holder.mTvAnalysis -->VISIBLE
                * */
                holder.mLayoutAnalysis.setVisibility(View.VISIBLE);
                if (!analysis.equals("")) {
                    holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                } else {
                    holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                }
                holder.mTvAnalysis.setTextColor(tvBlack);

            } else if (PaperID == 1) {

                if (mEntityCtfd.getClassicalQues() != null) {
                    //隐藏作答区域
                    holder.mLayoutStuAnswerEdt.setVisibility(View.GONE);
                    //显示题目回看解析内容
                    holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);
                    holder.mLayoutStuAnswer.setVisibility(View.GONE);
                    holder.mLayoutStuAssess.setVisibility(View.GONE);
                    //显示参考答案
                    for(int i=0;i<totalItemCount;i++){
                        TvAnswer[i] = new TextView(mContext);
                        TvAnswer[i].setText(Html.fromHtml(String.valueOf(i+1)+". "+smallAnswer[i]));
                        TvAnswer[i].setTextSize(16);
                        TvAnswer[i].setTextColor(tvGreen);
                        holder.mLayoutTvAnswer.addView(TvAnswer[i]);
                    }
                    //隐藏自评结果
                    holder.mLayoutStuAssess.setVisibility(View.GONE);
                    //显示答案解析
                    if (!analysis.equals("")) {
                        holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                    } else {
                        holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                    }

                } else {
                    if (status == 2 || status == 3) {

                        //显示题目回看解析内容
                        holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                         /*显示我的答案*/
                        holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                        if(stuAnswer.replaceAll("\\$、","").equals("")){
                            for(int i=0;i<totalItemCount;i++){
                                TvStuAnswer[i] = new TextView(mContext);
                                TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                                if(status==3) {
                                    TvStuAnswer[i].setTextColor(tvRed);
                                }else if(status==2){
                                    TvStuAnswer[i].setTextColor(tvBlue);
                                }
                                TvStuAnswer[i].setTextSize(16);
                                holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                            }
                        }else{
                            for(int i=0;i<totalItemCount;i++){
                                TvStuAnswer[i] = new TextView(mContext);
                                Log.e("====ABC===","===smallStuAnswer[i]=="+i+"========"+smallStuAnswer[i]);
                                if(status==3) {
                                    if (smallStuAnswer[i].equals(smallAnswer[i])) {
                                        TvStuAnswer[i].setTextColor(tvGreen);
                                    }else {
                                        TvStuAnswer[i].setTextColor(tvRed);
                                    }
                                }else if(status==2){
                                    TvStuAnswer[i].setTextColor(tvBlue);
                                }
                                if(!smallStuAnswer[i].equals("")){
                                    TvStuAnswer[i].setText(String.valueOf(i+1)+". "+smallStuAnswer[i]);
                                }else{
                                    TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                                }
                                TvStuAnswer[i].setTextSize(16);
                                holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                            }
                        }
                        /*显示参考答案*/
                        holder.mLayoutAnswer.setVisibility(View.VISIBLE);
                        for(int i=0;i<totalItemCount;i++){
                            TvAnswer[i] = new TextView(mContext);
                            TvAnswer[i].setText(Html.fromHtml(String.valueOf(i+1)+". "+smallAnswer[i]));
                            TvAnswer[i].setTextSize(16);
                            TvAnswer[i].setTextColor(tvGreen);
                            holder.mLayoutTvAnswer.addView(TvAnswer[i]);
                        }
                        //显示自评结果
                        if(status==2){
                    /*
                    * 显示自评选项
                    * 隐藏自评结果
                    * */
                            holder.mRgAssess.setVisibility(View.VISIBLE);
                            holder.mRBtnExcellent.setChecked(false);
                            holder.mRBtnGood.setChecked(false);
                            holder.mRBtnQualified.setChecked(false);
                            holder.mRBtnRange.setChecked(false);
                            if(stuAssess.equals("优秀")){
                                holder.mRBtnExcellent.setChecked(true);
                            }else  if(stuAssess.equals("良好")){
                                holder.mRBtnGood.setChecked(true);
                            }else  if(stuAssess.equals("合格")){
                                holder.mRBtnQualified.setChecked(true);
                            }else  if(stuAssess.equals("较差")){
                                holder.mRBtnRange.setChecked(true);
                            }
                            holder.mRgAssess.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                                @Override
                                public void onCheckedChanged(RadioGroup group, int checkedId) {
                                    if(checkedId==holder.mRBtnExcellent.getId()){
                                        stuAssess = "优秀";
                                    }else if(checkedId==holder.mRBtnGood.getId()){
                                        stuAssess = "良好";
                                    }else if(checkedId==holder.mRBtnQualified.getId()){
                                        stuAssess = "合格";
                                    }else if(checkedId==holder.mRBtnRange.getId()){
                                        stuAssess = "较差";
                                    }
                                    int anotherPaperID = -1;
                                    if(mEntityCtfd.getClassicalQues()!=null){
                                        anotherPaperID = PaperID-2;
                                    }else{
                                        anotherPaperID = PaperID-1;
                                    }
                                    mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                                }
                            });
                            holder.mTvStuAssess.setVisibility(View.GONE);
                        }else if(status==3){
                    /*
                    * 隐藏自评选项
                    * 显示自评结果
                    * */
                            holder.mRgAssess.setVisibility(View.GONE);
                            holder.mTvStuAssess.setVisibility(View.VISIBLE);

                            if(!stuAssess.equals("")) {
                                holder.mTvStuAssess.setText(stuAssess);
                            }else{
                                holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                            }

                        }

                        //答案解析
                        if(status==2){
                            holder.mLayoutAnalysis.setVisibility(View.GONE);
                        }else if(status==3){
                            holder.mLayoutAnalysis.setVisibility(View.VISIBLE);
                            if (!analysis.equals("")) {
                                holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                            } else {
                                holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                            }
                            holder.mTvAnalysis.setTextColor(tvBlack);
                        }

                    } else {
                        //显示作答区域
                        holder.mLayoutStuAnswerEdt.setVisibility(View.VISIBLE);
                        //关闭题目回看解析内容
                        holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
                    }
                }
            } else {
                if (status == 2 || status == 3) {
                    //显示题目回看解析内容
                    holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                    /*显示我的答案*/
                    holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                    if(stuAnswer.replaceAll("\\$、","").equals("")){

                        for(int i=0;i<totalItemCount;i++){
                            TvStuAnswer[i] = new TextView(mContext);
                            TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                            if(status==3) {
                                TvStuAnswer[i].setTextColor(tvRed);
                            }else if(status==2){
                                TvStuAnswer[i].setTextColor(tvBlue);
                            }
                            TvStuAnswer[i].setTextSize(16);
                            holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                        }
                    }else{
                        for(int i=0;i<totalItemCount;i++){
                            TvStuAnswer[i] = new TextView(mContext);
                            Log.e("====ABC===","===smallStuAnswer[i]=="+i+"========"+smallStuAnswer[i]);
                            if(status==3) {
                                if (smallStuAnswer[i].equals(smallAnswer[i])) {
                                    TvStuAnswer[i].setTextColor(tvGreen);
                                }else {
                                    TvStuAnswer[i].setTextColor(tvRed);
                                }
                            }else if(status==2){
                                TvStuAnswer[i].setTextColor(tvBlue);
                            }
                            if(!smallStuAnswer[i].equals("")){
                                TvStuAnswer[i].setText(String.valueOf(i+1)+". "+smallStuAnswer[i]);
                            }else{
                                TvStuAnswer[i].setText(String.valueOf(i+1)+". "+mContext.getString(R.string.znbk_no_answered));
                            }
                            TvStuAnswer[i].setTextSize(16);
                            holder.mLayoutTvStuAnswer.addView(TvStuAnswer[i]);
                        }
                    }
                     /*显示参考答案*/
                     holder.mLayoutAnswer.setVisibility(View.VISIBLE);
                    for(int i=0;i<totalItemCount;i++){
                        TvAnswer[i] = new TextView(mContext);
                        TvAnswer[i].setText(Html.fromHtml(String.valueOf(i+1)+". "+smallAnswer[i]));
                        TvAnswer[i].setTextSize(16);
                        TvAnswer[i].setTextColor(tvGreen);
                        holder.mLayoutTvAnswer.addView(TvAnswer[i]);
                    }
                    //显示自评结果
                    if(status==2){
                    /*
                    * 显示自评选项
                    * 隐藏自评结果
                    * */
                        holder.mRgAssess.setVisibility(View.VISIBLE);
                        holder.mRBtnExcellent.setChecked(false);
                        holder.mRBtnGood.setChecked(false);
                        holder.mRBtnQualified.setChecked(false);
                        holder.mRBtnRange.setChecked(false);
                        if(stuAssess.equals("优秀")){
                            holder.mRBtnExcellent.setChecked(true);
                        }else  if(stuAssess.equals("良好")){
                            holder.mRBtnGood.setChecked(true);
                        }else  if(stuAssess.equals("合格")){
                            holder.mRBtnQualified.setChecked(true);
                        }else  if(stuAssess.equals("较差")){
                            holder.mRBtnRange.setChecked(true);
                        }
                        holder.mRgAssess.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(RadioGroup group, int checkedId) {
                                if(checkedId==holder.mRBtnExcellent.getId()){
                                    stuAssess = "优秀";
                                }else if(checkedId==holder.mRBtnGood.getId()){
                                    stuAssess = "良好";
                                }else if(checkedId==holder.mRBtnQualified.getId()){
                                    stuAssess = "合格";
                                }else if(checkedId==holder.mRBtnRange.getId()){
                                    stuAssess = "较差";
                                }
                                int anotherPaperID = -1;
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    anotherPaperID = PaperID-2;
                                }else{
                                    anotherPaperID = PaperID-1;
                                }
                                mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                            }
                        });
                        holder.mTvStuAssess.setVisibility(View.GONE);
                    }else if(status==3){
                    /*
                    * 隐藏自评选项
                    * 显示自评结果
                    * */
                        holder.mRgAssess.setVisibility(View.GONE);
                        holder.mTvStuAssess.setVisibility(View.VISIBLE);

                        if(!stuAssess.equals("")) {
                            holder.mTvStuAssess.setText(stuAssess);
                        }else{
                            holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                        }

                    }

                    //答案解析
                    if(status==2){
                        holder.mLayoutAnalysis.setVisibility(View.GONE);
                    }else if(status==3){
                        holder.mLayoutAnalysis.setVisibility(View.VISIBLE);
                        if (!analysis.equals("")) {
                            holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                        } else {
                            holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                        }
                        holder.mTvAnalysis.setTextColor(tvBlack);
                    }
                } else {
                    //显示作答区域
                    holder.mLayoutStuAnswerEdt.setVisibility(View.VISIBLE);
                    //关闭题目回看解析内容
                    holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
                }
            }
        }
    }

    /*
    * 写入作答信息
    * */
    private void setIntoStuAnswer(String strStuAnswer,int currentEdt){

        String allStuAnswer = "";

        if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){

            smallStuAnswer[currentEdt] = strStuAnswer;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    allStuAnswer=smallStuAnswer[0];
                }else{
                    allStuAnswer = allStuAnswer + "$、" + smallStuAnswer[i];
                }
            }

            for(int i=0;i<totalItemCount;i++){

                if(!smallStuAnswer[i].equals("")){
                    mEntityNtxl.setAnswerState(1);
                    TrainingDifficultProblemsPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                    break;
                }else{
                    mEntityNtxl.setAnswerState(0);
                    TrainingDifficultProblemsPaperActivity.mSbtnSubmit.setTextColor(tvGray);
                }
            }

            Log.e("==SmaStuAnswer==0000==",smallStuAnswer[currentEdt]);
            Log.e("=allStuAnswer===1111==",allStuAnswer);
            mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(allStuAnswer);

        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){

            smallStuAnswer[currentEdt] = strStuAnswer;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    allStuAnswer=smallStuAnswer[0];
                }else{
                    allStuAnswer = allStuAnswer + "$、" + smallStuAnswer[i];
                }
            }

            Log.e("===WGL123====","====PaperID==="+PaperID);
//            String UpLoadPath = mEntityCtfd.getRecQues().get()
            String allStuAnswerString = allStuAnswer.replaceAll("\\$、","");
            Log.e("===WGL123444====","====allStuAnswerString==="+allStuAnswerString);
            if(!allStuAnswerString.equals("")) {
                mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
            }else{
                mEntityCtfd.getRecQues().get(0).setAnswerState(0);
                WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvGray);
            }

            Log.e("==SmaStuAnswer==0000==",smallStuAnswer[currentEdt]);
            Log.e("=allStuAnswer===1111==",allStuAnswer);
            int RecPaperID = -1;
            if(mEntityCtfd.getClassicalQues()!=null) {
                RecPaperID = PaperID- 2;
            }else{
                RecPaperID = PaperID - 1;
            }
            Log.e("==9999====RecPaperID==",""+RecPaperID);
            mEntityCtfd.getRecQues().get(RecPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(allStuAnswer);

        }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){

            smallStuAnswer[currentEdt] = strStuAnswer;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    allStuAnswer=smallStuAnswer[0];
                }else{
                    allStuAnswer = allStuAnswer + "$、" + smallStuAnswer[i];
                }
            }

            for(int i=0;i<totalItemCount;i++){

                if(!smallStuAnswer[i].equals("")){
                    mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                    SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                    break;
                }else{
                    mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(0);
                    SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvGray);
                }
            }

            Log.e("==SmaStuAnswer==0000==",smallStuAnswer[currentEdt]);
            Log.e("=allStuAnswer===1111==",allStuAnswer);
            mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).setSubChildStuAnswer(allStuAnswer);

        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){

            smallStuAnswer[currentEdt] = strStuAnswer;
            for(int i=0;i<totalItemCount;i++){
                if(i==0){
                    allStuAnswer=smallStuAnswer[0];
                }else{
                    allStuAnswer = allStuAnswer + "$、" + smallStuAnswer[i];
                }
            }

            for(int i=0;i<totalItemCount;i++){

                if(!smallStuAnswer[i].equals("")){
                    mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                    WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                    break;
                }else{
                    mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(0);
                    WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvGray);
                }
            }

            Log.e("==SmaStuAnswer==0000==",smallStuAnswer[currentEdt]);
            Log.e("=allStuAnswer===1111==",allStuAnswer);
            mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).setSubChildStuAnswer(allStuAnswer);

        }
    }
}